import koa from 'koa'
 import Router from 'koa-router'
 import  moment from 'moment'
 import en1 from './en1.js'

 let app = new koa()
 let router = new Router()

 
 function en(req,res){
  if(req.headers['x-auth-token=valid-token-123']){

  }else{
    req.status = 404
    req.body = {
    "error":"Unauthorized",
    "message":"invalid or missing token"
    }
  }

 }
 router.get('/',async(req,res)=>{
  req.headers['x-auth-token'] = 'valid-token-123'
   req.body = {"hello":"你好"}
    let date =  new Date()
    console.log(`[info] [${moment(date).format("yyyy-MM-DD hh:mm:kk")}] ${req.method} ${req.url}`);
    console.log(req.headers['x-auth-token']);
    if(req.headers['x-auth-token']==['valid-token-123']){

    }else{
      req.status = 404
      req.body = {
      "error":"Unauthorized",
      "message":"invalid or missing token"
      }
    }
    
    
 })
 
 router.get('/users',async(req,res)=>{
  let id = req.url.split('/')[2]
req.body = en1.filter(item=>item.id = id )[0]
if(req.headers['x-auth-token=valid-token-123']){

}else{
  req.status = 404
  req.body = {
  "error":"Unauthorized",
  "message":"invalid or missing token"
  }
}
 })



 app.use(router.routes())
 app.listen(8001)